import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

// 创建动物接口，定义特定行为
interface AnimalBehavior {
    void performAction();
}

// 创建基础的动物类
class Animal {
    private String name;
    private int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }
}

// 创建鸟类
class Bird extends Animal implements AnimalBehavior {
    public Bird(String name, int age) {
        super(name, age);
    }

    @Override
    public void performAction() {
        System.out.println(getName() + " 正在飞.");
    }
}

// 创建哺乳动物类
class Mammal extends Animal implements AnimalBehavior {
    public Mammal(String name, int age) {
        super(name, age);
    }

    @Override
    public void performAction() {
        System.out.println(getName() + " 正在跑.");
    }
}

// 创建特定鸟类，如鹦鹉
class Parrot extends Bird {
    public Parrot(String name, int age) {
        super(name, age);
    }

    @Override
    public void performAction() {
        System.out.println(getName() + " 可以模仿人类说话.");
    }
}

// 创建动物园管理系统界面
class ZooGUI extends JFrame {
    private List<Animal> animals = new ArrayList<>();

    public ZooGUI() {
        setTitle("动物园管理系统————高辉");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

        JButton birdButton = new JButton("天上飞的");
        JButton mammalButton = new JButton("地上跑的");

        birdButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (Animal animal : animals) {
                    if (animal instanceof Bird) {
                        ((Bird) animal).performAction();
                    }
                }
            }
        });

        mammalButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for (Animal animal : animals) {
                    if (animal instanceof Mammal) {
                        ((Mammal) animal).performAction();
                    }
                }
            }
        });

        add(birdButton);
        add(mammalButton);

        setVisible(true);
    }

    public void addAnimal(Animal animal) {
        animals.add(animal);
    }

    public static void main(String[] args) {
        ZooGUI zoo = new ZooGUI();
        zoo.addAnimal(new Parrot("鹦鹉", 5));
        zoo.addAnimal(new Bird("麻雀", 2));
        zoo.addAnimal(new Mammal("狮子", 7));
    }
}

public class ZooManagementSystem {
    public static void main(String[] args) {
        // 创建动物
        Bird sparrow = new Bird("麻雀", 2);
        Mammal lion = new Mammal("狮子", 7);
        Parrot polly = new Parrot("鹦鹉", 5);

        // 执行特定行为
        sparrow.performAction();
        lion.performAction();
        polly.performAction();
    }
}